package cn.cloud9.designpattern.dp06facade.facade;

import cn.cloud9.designpattern.dp06facade.po.GiftInfo;
import cn.cloud9.designpattern.dp06facade.service.LogisticsService;
import cn.cloud9.designpattern.dp06facade.service.PaymentService;
import cn.cloud9.designpattern.dp06facade.service.QualifyService;

/**
 * @projectName: Java
 * @author: 戴知舟
 * @date: 2022年05月24日 10:29
 * @version: 1.0
 */
public class FacadePattern {
    private QualifyService qualifyService = new QualifyService();
    private PaymentService payment = new PaymentService();
    private LogisticsService logisticsService = new LogisticsService();

    /**
     * 门面模式就是统一起来处理，屏蔽了过程？？？
     * @param giftInfo
     * @return void
     * @author 戴知舟
     * @createTime 2022/5/24 10:31
     *
     */
    public void exchange(GiftInfo giftInfo) {
        // 检查库存是否可用
        boolean available = qualifyService.isAvailable(giftInfo);
        if (!available)  return;

        // 如果足够则开始发起支付服务
        boolean isSuccessPay = payment.pay(giftInfo);
        if (!isSuccessPay) return;

        // 交易成功，开始生成物流订单
        String delivery = logisticsService.delivery(giftInfo);
        System.out.println(delivery);
    }

}
